<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>35题查询天数</title>
    <style>
        div {
            width: 100%;
            
        }
        span {
            display: block;
            width: 100%;
        }
    </style>
    <script>
        var month = 0;
        var year = 0;
        function getDays(flag) {
            //获取月份
            if (!month) {
                month = prompt(flag ? '请输入正确的月份1<=x<=12' : '请输入月份');
            }
            if (!/^[0-9]*$/i.test(month)) {
                month = 0;
                getDays(true);
                return;
            }
            month = parseInt(month);
            if (month < 1 || month > 12) {
                month = 0;
                getDays(true);
                return;
            }

            //如果是2月，获取年份
            if (month === 2 && !year) {
                year = prompt(flag ? '请输入正确的月份1900<=x' : '您的月份为2月，请输入年份');
            }
            if (!/^[0-9]*$/i.test(year)) {
                year = 0;
                getDays(true);
                return;
            }
            year = parseInt(year);
            //计算是否是闰年
            let isRunYear = getRunYear();

            let span = document.getElementById('span');
            let bigMonth = [1, 3, 5, 7, 8, 10, 12];
            if (month === 2) {
                if (isRunYear) {
                    span.innerHTML = `${year}年2月是闰年，当月29天`;
                } else {
                    span.innerHTML = `${year}年2月不是闰年，当月28天`;
                }
            } else {
                if (bigMonth.indexOf(month) >= 0) {
                    span.innerHTML = `${month}月，当月31天`;
                } else {
                    span.innerHTML = `${month}月，当月30天`;
                }
            }
            month = 0;
            year = 0;
        }

        // 判断是否是闰年
        function getRunYear() {
            if (year === 0) return false;     
            let rs = year % 100;
            let ops = 0;
            // 非整百年份
            if (rs > 0) {
                ops = 4;
            } else {
                ops = 400;
            }

            let result = year % ops;
            return result > 0;
        }
    </script>
</head>
<body>
    <div>
        点击按钮开始输入月份<input type="button" value="点击输入" onclick="getDays()">
        <span id="span"></span>
    </div>
</body>
</html>